﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraysAndStrings.SetZeroes
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[][] nums = new int[][]
            {
                new int[] { 1,2,3} ,
                new int[] { 4,0,6} ,
                new int[] { 7,8,9} ,
            };
            SetZeroes(nums);
            foreach (var item in nums)
            {
                foreach (var item1 in item)
                {
                    Console.WriteLine(item1);
                }
            }
            //Console.WriteLine();
            Console.ReadKey();
        }
        public static void SetZeroes(int[][] matrix)
        {
            Queue<int[]> que = new Queue<int[]>();
            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    if (matrix[i][j] == 0)
                    {
                        que.Enqueue(new int[] { i, j, matrix[i][j] });
                    }
                }
            }
            while (que.Count > 0)
            {
                int[] array = que.Dequeue();
                for (int i = 0; i < matrix.Length; i++)
                {
                    for (int j = 0; j < matrix[i].Length; j++)
                    {
                        if (array[0] == i || array[1]==j)
                        {
                            matrix[i][j] = 0;
                        }
                    }
                }
            }
        }
    }
}
